// 解决级联回显问题
/**
 * 根据menuId遍历获取menuId有关对象的父id
 */

export function getParentNodes(id, tree) {
    let nodes = [];
    _getParentNodes([], id, tree);
    return nodes;
}
 
function _getParentNodes(his, targetId, tree) {
    tree.some((list) => {
        const children = list.children || [];
        if (list.menuId === targetId) {
            nodes = his;
            return true;
        } else if (children.length > 0) {
            const history = [...his];
            history.push(list);
            return _getParentNodes(history, targetId, children);
        }
    })
}